package com.ithei.date.集合;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

public class MyCollection {
    public static void main(String[] args) {
        ArrayList<String> list = new ArrayList<String>();
        list.add("龟田大朗");
        list.add("龟田次朗");
        list.add("龟田太朗");
        list.add("ddd");
        list.add("eee");
        //迭代器迭代集合
        Iterator<String> iterator = list.iterator();
        while (iterator.hasNext()) {
            System.out.println(iterator.next());
        }
        iterator = list.iterator();
        while (iterator.hasNext()) {
            System.out.println(iterator.next());
        }
        System.out.println("..............");
        //增强for底层原理是迭代器
        for (String s : list) {
            System.out.println(s);
        }
        System.out.println(list.size());
        System.out.println(list);
        boolean ddd = list.remove("ddd");
        System.out.println(ddd);
        System.out.println(list);
        if (list.contains("龟田大朗")) {
            list.remove("龟田大朗");
        }
        boolean removeIf = list.removeIf((String s) -> {
            if (s == "龟田大朗") {
                return true;
            } else {
                return false;
            }
        });
        boolean removeIf1 = list.removeIf((String s) -> {
            if (new StringBuilder(s).indexOf("太") != -1) {
                return true;
            } else {
                return false;
            }
        });
        System.out.println(removeIf1);
        System.out.println(list + "  ..........查看...........");
        System.out.println(removeIf);
        System.out.println(list);
        boolean ddd1 = list.contains("ddd");
        System.out.println(ddd1);
        list.clear();
        System.out.println(list);
        boolean empty = list.isEmpty();
        System.out.println(empty);
        System.out.println(list.size());

    }
}

class Collection集合 {
    public static void main(String[] args) {
        Collection<String> collection = new ArrayList<String>();
        collection.add("aaa");
        collection.add("aaa");
        collection.add("aaa");
        collection.add("aaa");
        collection.add("bbb");
        collection.add("ccc");
        collection.add("ddd");
        System.out.println(collection);
        boolean bl = collection.remove("ddd");
        //System.out.println(bl);
        Iterator<String> iterator = collection.iterator();
        while (iterator.hasNext()) {
            //iterator.remove();
            String s = iterator.next();
            System.out.println(s);
        }

        System.out.println("..................................");
        for (String s : collection) {
            System.out.println(s);
        }
        System.out.println(collection);
    }
}

class Collectionsss {
    public static void main(String[] args) {
        ArrayList<String> list = new ArrayList<String>();
        list.add("a");
        list.add("b");
        list.add("b");
        list.add("c");
        list.add("d");
        list.add("e");
        list.add("f");
        for (int i = 0; i < list.size(); i++) {
            if (list.get(i).equals("b")) {
                list.remove(i);
                i--;
            }
        }
    }
}

class Collectionssss {
    public static void main(String[] args) {
        ArrayList<String> list = new ArrayList<String>();
        list.add("a");
        list.add("b");
        list.add("b");
        list.add("c");
        list.add("d");
        list.add("e");
        list.add("f");
        System.out.println(list);
        Iterator<String> iterator = list.iterator();
        while (iterator.hasNext()) {
            String s = iterator.next();
            if (s.equals("b")) {
                iterator.remove();
            }
        }
        System.out.println(list);
    }
}

